<?php

class Vote extends CI_Model {

    var $fb_user_id = '';
    var $product_id = '';
    var $voted_date = '';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function setVoteInfo($user_id, $product_id) {
        $this->fb_user_id = $user_id;
        $this->product_id = $product_id;
    }

    function get_data() {
        $query = $this->db->get('user_vote', 10);
        return $query->result();
    }
    function get_data_via_userid($user_id)
    {
        $this->db->select('product_id');
        $query = $this->db->get_where('user_vote', array('fb_user_id' => $user_id));
        $result= array();
        foreach($query->result() as $row)
        {
            $result[]=$row->product_id;
        }
        return $result;
    }

    function insert_vote() {
        $query = $this->db->query('SELECT fb_user_id FROM user_vote where fb_user_id=' . $this->fb_user_id . ' and product_id=' . $this->product_id);
        if ($query->num_rows() > 0) {
            
        } else {
            $this->voted_date = date('Y-m-d H:i:s');

            $this->db->insert('user_vote', $this);
        }
    }

    function update_vote($id) {
        $this->voted_date = date('Y-m-d H:i:s');

        $this->db->update('user_vote', $this, array('fb_user_id' => $id));
    }

}

?>
